package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.BusinessAbodeMapper;
import com.koron.css2.baseConfig.vo.SelectVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toList;

/**
 * 营业网点查询
 * @author bin
 *
 */
public class ServAreaOpList implements ServerInterface{

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
		try {
			BusinessAbodeMapper mapper = factory.getMapper(BusinessAbodeMapper.class,"_default");
			List<SelectVO> list = mapper.businessAbodeSelect(userInfo.getCurWaterCode());
			List<Map<String, String>> result = list.stream().parallel().map(t -> {
				Map<String, String> data = new HashMap<String, String>();
				data.put("name", t.getName());
				data.put("value", t.getId());
				return data;
			}).collect(toList());
			info.setData(result);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}
}
